<template>
  <div id='login_container'></div>
</template>
<script>
export default {
  name: 'login',
  mounted () {
    const url = encodeURIComponent('http://localhost:8081/#/home')
    const goto = encodeURIComponent(
      'https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=dingoap9nku1p1dxrcjvzx&response_type=code&scope=snsapi_login&state=STATE&redirect_uri=' + url
    )
    var obj = DDLogin({
      id: 'login_container',
      goto: goto,
      style: 'border:none;background-color:#FFFFFF;',
      width: '365',
      height: '400'
    })
    var hanndleMessage = function (event) {
      var origin = event.origin
      console.log('origin', event.origin)
      if (origin === 'https://login.dingtalk.com') {
        var loginTmpCode = event.data
        window.location.href = 'https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=dingoap9nku1p1dxrcjvzx&response_type=code&scope=snsapi_login&state=STATE&redirect_uri=http://localhost:8080/home&loginTmpCode=' + loginTmpCode
      }
    }
    if (typeof window.addEventListener !== 'undefined') {
      window.addEventListener('message', hanndleMessage, false)
    } else if (typeof window.attachEvent !== 'undefined') {
      window.attachEvent('onmessage', hanndleMessage)
    }
  }
}
</script>
<style scoped>
</style>
